import java.util.Stack;

public class Solution682 {
    public int calPoints(String[] ops) {
        Stack<Integer> stack=new Stack<>();
        int ans=0;
        for (String op : ops) {
            if (op.equals("+")){
                int a=stack.pop();
                int b=stack.pop();
                ans+=a+b;
                stack.push(b);
                stack.push(a);
                stack.push(a+b);
            }else if (op.equals("D")){
                int a=stack.pop();
                ans+=a*2;
                stack.push(a);
                stack.push(a*2);
            }else if (op.equals("C")){
                ans-=stack.pop();
            }else{
                int a=Integer.parseInt(op);
                ans+=a;
                stack.push(a);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution682().calPoints(new String[]{"5","2","C","D","+"}));
    }
}
